<?php

include_once "xAP-functions/webincludes.php";
include_once "Weather/Timer.php";

$id=intval($_POST["id"]);
$url=strtolower($_POST["url"]);
$delete=intval($_POST["delete"]);

echo webpageheader();

if ($delete==1){
	dbexec("delete from xAP_Weather_Source where SourceID=".$id);
	dbexec("delete from xAP_Weather_Log where SourceID=".$id);
	dbexec("delete from xAP_Weather_Forecast where SourceID=".$id);
}
else
{
$u=explode("/",$url);
$source="BBC";
$sourceref= intval($u[count($u)-1]);
$sourcetype= $u[count($u)-2];
	if ($sourceref>0){
		if($id==0){
		$sql="insert into xAP_Weather_Source (Source,SourceRef,SourceType,Active) VALUES (
		'".$source."',
		".$sourceref.",
		'".dbesc($sourcetype)."',
		1
		)";
		
		
		}else{
		$sql="update xAP_Weather_Source set 
		SourceRef=".$sourceref.",
		SourceType='".dbesc($sourcetype)."',
		Source='".$source."',
		Location='Updating',
		DateStamp=''
		
		where SourceID=".$id;
		
		}
		dbexec($sql);
		//echo $sql;
		WeatherImport($id);
		}
}


//header("Location:config_setup.php");
//
echo "<script>
window.location ='config_setup.php';
</script>";

echo webpagefooter();
?>